//
//  StringViewController.swift
//  SwiftTest
//
//  Created by midea on 16/3/8.
//  Copyright © 2016年 Vincent. All rights reserved.
//

import Foundation
import UIKit

class StringViewController : BaseViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.titles = ["emptyStatement","elongate","ergodic","compare","suffixAndPrefix","textTransform"]
        self.tableView?.reloadData()
        
    }
    
    fileprivate func emptyStatement() {
        let stringA = ""
        if stringA.isEmpty {
            print("This is empty stringA")
        }
        
        let stringB = String()
        if stringB.isEmpty {
            print("This is empty stringB")
        }
    }
    
    fileprivate func elongate() {
        var string = "hello"
        string += " world"
        print(string)
    }
    
    fileprivate func ergodic() {
        let string : String = "string"
        let count = string.lengthOfBytes(using: String.Encoding.utf8)
        print("'string' count : " + String(count))
    }
    
    fileprivate func compare() {
        let stringA = "string"
        let stringB = "string"
        if stringA == stringB {
            print("stringA is equal to stringB")
        }
    }
    
    fileprivate func suffixAndPrefix(){
        let string = "hello world"
        if string.hasPrefix("hello") {
            print("stirng has prefix ‘hello’")
        }
        if string.hasSuffix("world") {
            print("stirng has prefix 'world'")
        }
    }
    
    fileprivate func textTransform() {
        let string = "This String Has MORE characters"
        print(string.uppercased())
        print(string.lowercased())
    }
    
    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        super.tableView(tableView, didSelectRowAt: indexPath)
        
        switch indexPath.row{
        case 0:
            emptyStatement()
        case 1:
            elongate()
        case 2:
            ergodic()
        case 3:
            compare()
        case 4:
            suffixAndPrefix()
        case 5:
            textTransform()
        default:
            print("no more methods")
        }
    }
}
